package cn.itcast.consumer.web;

import cn.itcast.consumer.clients.UserClient;
import cn.itcast.consumer.config.RedisProperties;
import cn.itcast.consumer.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 虎哥
 */
@RestController
@RequestMapping("consumer")
public class ConsumerController {

  /*  @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/rest/{id}")
    public User consumerUserById(@PathVariable("id") Long id){
        String url = "http://user-service/user/" + id;
        return restTemplate.getForObject(url, User.class);
    }
    */

    @Autowired
    private UserClient userClient;

    @Autowired
    private RedisProperties redisProperties;

    @GetMapping("/rest/{id}")
    public User consumerUserById(@PathVariable("id") Long id){
        return userClient.queryById(id);
    }

    @GetMapping("/hello")
    public RedisProperties disUserById(){
        return redisProperties;
    }

    @GetMapping("/hi")
    public String hi(){
        return "<h1>欢迎来到传智播客，http://www.itcast.cn！</h1>";
    }
}
